<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>组织结构设置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <!--引入本地的css样式-->
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/css/admin.css" media="all">

</head>
<body>
<form id="myForm" class="layadmin-user-login-box layadmin-user-login-body layui-form" action="" style="padding: 20px;">
<div class="layui-form-item">
    <label class="layui-form-label">组织全称</label>
    <div class="layui-input-inline">
        <input type="text" name="dept_full_name" lay-verify="required" placeholder="请输入组织全称" autocomplete="off"
               class="layui-input">
    </div>
    <label class="layui-form-label">组织简称</label>
    <div class="layui-input-inline">
        <input type="text" name="dept_short_name" lay-verify="required" placeholder="请输入组织简称" autocomplete="off"
               class="layui-input">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">所属组织</label>
    <div class="layui-input-inline">
        <input type="text" name="dept_father" lay-verify="required" placeholder="请输入所属组织" autocomplete="off"
               class="layui-input">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">地址</label>
    <div class="layui-input-block">
        <input name="dept_address" lay-verify="required" placeholder="请输入地址" class="layui-input">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">简介</label>
    <div class="layui-input-block">
        <textarea name="common" lay-verify="required" placeholder="请输入简介" class="layui-textarea"></textarea>
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">备注</label>
    <div class="layui-input-block">
        <textarea name="remark" lay-verify="required" placeholder="请输入备注" class="layui-textarea"></textarea>
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">是否启用</label>
    <div class="layui-input-block">
        <input type="radio" name="start" value="1" title="是">
        <input type="radio" name="start" value="0" title="否" checked>
    </div>
</div>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="submit">保存</button>

        <button type="button" class="layui-btn layui-btn-primary" onclick="cancelForm()">取消</button>
    </div>
</div>
</form>
<script type="text/javascript" src="../../static/js/jquery-3.6.0.min.js"></script>
<!--引入本地layui.js-->
<script src="../../static/layui/layui.js"></script>
<script type="text/javascript">
    // 取消按钮点击事件
    function cancelForm() {
        // 取消表单逻辑
        document.getElementById("myForm").reset(); // 清除表单数据
    }
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(submit)', function (data) {
            console.log("有数据吗？")
            console.log(data.field)
            console.log(data.field.dept_full_name)
            $.ajax({
                url:"/system/adddepartment",
                type:"post",
                data:data.field,
                dataType:"json",
                success:function (res) {//res响应回来数据
                    if(res.code == 200){//code=200登录成功
                        //1.弹出提示信息
                        layer.msg('添加成功',{
                            offset:'15px',
                            icon:1,
                            time:1000
                        },function () {
                            window.location.reload();
                        });
                    }
                    if(res.code == 401){
                        alert(res.msg);
                    }
                    if(res.code == 500){//数据插入失败
                        alert(res.msg);
                    }
                    if(res.code == 501){//系统开小差，请联系管理员
                        alert(res.msg);
                    }
                }
            })
            /*:form.on()表单监控事件中一定要加 return false;
            如果不加的话,后端不会报错,而前端代码中不会运行到success中,
            不同浏览器也有不同效果,谷歌浏览器有时会报错,火狐和其他浏览器100%报错*/
            return false;
        });
    });
</script>
</body>

</html>